package com.cs410.collabwriting.tools;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class LogManager {

	private static String ERROR_MESSAGE_HEADER = "[ERROR]";
	private static String INFO_MESSAGE_HEADER = "[INFO]";
	private static String WARNING_MESSAGE_HEADER = "[WARNING]";
	private static String DEBUG_MESSAGE_HEADER = "[DEBUG";
	
	public static int LOG_LEVEL_3 = 3;
	public static int LOG_LEVEL_2 = 2;
	public static int LOG_LEVEL_1 = 1;
	
	
	public static void logInfo( String Message ) {
		System.out.println( INFO_MESSAGE_HEADER + " " + Message );
	}
	
	public static void logError( String Message ) {
		System.err.println( ERROR_MESSAGE_HEADER + " " + Message );
	}
	
	public static void logDebug( String Message , int level ) {
		Properties debugProperty = new Properties();
		InputStream debugInput;
		int logDebugMessage = 0;
		try {
			debugInput = LogManager.class.getClassLoader().getResourceAsStream("config.properties");
			debugProperty.load( debugInput );
			String debugMessage = debugProperty.getProperty("LOG_DEBUG_MESSAGE");
			if( debugMessage != null ) {
				logDebugMessage = Integer.parseInt( debugMessage.trim() );
			}
		} catch ( IOException exception ) {
			System.out.println( DEBUG_MESSAGE_HEADER + level + "] [ERROR]" + exception.getMessage() );
		}
		
		if( level <= logDebugMessage ) {
			System.out.println( DEBUG_MESSAGE_HEADER + level + "] " + Message );
		}
	}
	
	public static void logWarning( String Message ) {
		System.err.println( WARNING_MESSAGE_HEADER + " " + Message );
	}
	
}
